package observerPattern.modify;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import observerPattern.old.CurrentConditions;

import java.util.ArrayList;

/**
 * @author： pang-yun
 * @date： 2021-10-25 17:21
 * 功能目的 ：用于
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WeatherData implements Subject {
    // 最新的 天气信息
    private float temperature;
    private float pressure;
    private float humidity;

    // 前台展示的信息
    private ArrayList<Observer> observers;


    // 当前数据有更新时
    public void setData(float temperature, float pressure, float humidity){
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        observers.stream().forEach(observer -> {
            observer.update(temperature,pressure,humidity);
        });
    }


    @Override
    public void registerObserver(Observer o) {
        observers.add(o);
    }

    @Override
    public void removeObserver(Observer o) {
        observers.remove(o);
    }

    @Override
    public void notifyObservers() {
    }
}
